package com.newtouch.bxzs.business.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.product.model.*;
import com.newtouch.bxzs.business.product.service.RecommendationService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 建议书的控制层
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/11 14:52</td>
 * <td>lanwei</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lanwei
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "建议书")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/recommendationController")
public class RecommendationController {
    /**
     * 静态变量：系统日志
     */
    private static final Log logger = LogFactory.getLog(ProductController.class);

    @Resource
    private RecommendationService recommendationService;

    @ApiOperation(value = "查看建议书详情")
    @ApiImplicitParam(name = "recommendationId", value = "建议书id", paramType = "String")
    @GetMapping("/getRecommendationDetail")
    public BaseResponse<RecommendationDetailBO> getRecommendationDetail(@RequestParam(value = "recommendationId") String recommendationId) {
        logger.info("查看建议书详情");
        return RespGenerator.returnOK(recommendationService.getRecommendationDetail(recommendationId));
    }

    @ApiOperation(value = "查询建议书列表")
    @PostMapping("/getRecommendationList")
    @MyLog(systemFunctionName = "建议书", systemFunctionUrl = "/recommendationController/getRecommendationList", userOperationType = 4, userOperationSummary = "查询建议书列表")
    public BaseResponse<RecommendationPagingListBO> getRecommendationList(@RequestBody RecommendationVO recommendationVO) {
        logger.info("查询建议书列表");
        return RespGenerator.returnOK(recommendationService.getRecommendationList(recommendationVO));
    }

    @ApiOperation(value = "对比建议书")
    @PostMapping("/compareRecommendation")
    public BaseResponse<List<RecommendationDetailBO>> compareRecommendation(@RequestBody @ApiParam(name = "recommendationIds", value = "建议书id集合", required = true) List<String> recommendationIds) {
        logger.info("对比建议书");
        return RespGenerator.returnOK(recommendationService.compareRecommendation(recommendationIds));
    }

    @ApiOperation(value = "保存建议书")
    @PostMapping("/modifyRecommendation")
    @MyLog(systemFunctionName = "建议书", systemFunctionUrl = "/recommendationController/modifyRecommendation", userOperationType = 4, userOperationSummary = "保存建议书")
    public BaseResponse<String> modifyRecommendation(@RequestBody ModifyRecommendationVO modifyRecommendationVO) {
        logger.info("保存建议书");
        return RespGenerator.returnOK(recommendationService.modifyRecommendation(modifyRecommendationVO));
    }

    @ApiOperation(value = "保费试算")
    @PostMapping("/premiumTrial")
    @MyLog(systemFunctionName = "建议书", systemFunctionUrl = "/recommendationController/premiumTrial", userOperationType = 4, userOperationSummary = "保费试算")
    public BaseResponse<List<PremiumTrialBO>> premiumTrial(@RequestBody @ApiParam(name = "List<PremiumTrialVO>", value = "保费试算VO类集合", required = true) List<PremiumTrialVO> premiumTrialVOList) {
        logger.info("保费试算");
        return RespGenerator.returnOK(recommendationService.getPremiumCalculation(premiumTrialVOList));
    }

    @ApiOperation(value = "制作建议书")
    @PostMapping("/makeRecommendation")
    @MyLog(systemFunctionName = "建议书", systemFunctionUrl = "/recommendationController/makeRecommendation", userOperationType = 1, userOperationSummary = "制作建议书")
    public BaseResponse<MakeRecommendationOnAppBO> makeRecommendation(@RequestBody MakeRecommendationVO makeRecommendationVO) {
        logger.info("制作建议书");
        return RespGenerator.returnOK(recommendationService.makeRecommendation(makeRecommendationVO));
    }

    @ApiOperation(value = "产品推荐")
    @PostMapping("/recommendProduct")
    @MyLog(systemFunctionName = "建议书", systemFunctionUrl = "/recommendationController/recommendProduct", userOperationType = 1, userOperationSummary = "制作建议书")
    public BaseResponse<IPage<ProductBO>> recommendProduct(@RequestBody ProductRecommendVO productRecommendVO) {
        logger.info("产品推荐");
        return RespGenerator.returnOK(recommendationService.recommendProduct(productRecommendVO));
    }

    @ApiOperation(value = "根据建议书关联id查询建议书数量")
    @GetMapping("/getRecommendationByRelationId")
    @ApiIgnore
    Integer getRecommendationByRelationId(@RequestParam String relationId){
        return recommendationService.getRecommendationByRelationId(relationId);
    }
}
